package com.wcll.www;
import java.sql.*;
import java.util.*;

public class AdminBean {
	private int id;
	private String ad_name;
	private String ad_password;
	private int phone;
	private String ip;
	private java.util.Date  create_time;
	private static Connection con=null;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getAd_name() {
		return ad_name;
	}
	public void setAd_name(String ad_name) {
		this.ad_name = ad_name;
	}
	public String getAd_password() {
		return ad_password;
	}
	public void setAd_password(String ad_password) {
		this.ad_password = ad_password;
	}
	public int getPhone() {
		return phone;
	}
	public void setPhone(int phone) {
		this.phone = phone;
	}
	public String getIp() {
		return ip;
	}
	public void setIp(String ip) {
		this.ip = ip;
	}
	public java.util.Date getCreate_time() {
		return create_time;
	}
	public void setCreate_time(java.util.Date create_time) {
		this.create_time = create_time;
	}
	public static Connection getCon() throws ClassNotFoundException, SQLException {
		if(con==null){
			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection("jdbc:mysql://localhost/jobs?useUnicode=true&characterEncoding=UTF8","root","");
		}
		return con;
	}
	public static void setCon(Connection con) {
		AdminBean.con = con;
	}
	public ArrayList<AdminBean> getAdmin(){
		ArrayList<AdminBean> ab = new ArrayList<AdminBean>();
		try{
			con = AdminBean.getCon();
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("select * from job_admins");
			while(rs.next()){
			AdminBean a = new AdminBean();
			a.setId(rs.getInt("id"));
			a.setAd_name(rs.getString("ad_name"));
			a.setAd_password(rs.getString("ad_password"));
			a.setIp(rs.getString("ip"));
			a.setPhone(rs.getInt("phone"));
			a.setCreate_time(new java.util.Date(rs.getDate("create_time").getTime()));
			ab.add(a);
			}
			rs.close();
			st.close();
		}catch(Exception e){}
		return ab;
	}
	public boolean deleAdmin(int id){
		boolean flags = false;
		try{
			con = AdminBean.getCon();
			Statement st = con.createStatement();
			st.execute("delete from job_admins where id="+id);
			if(st.getUpdateCount()==1){
				flags = true;
			}
		}catch(Exception e){}
		return flags;
	}
	public boolean yanZheng(String user,String pass){
		boolean bl = false;
		try{
			con = AdminBean.getCon();
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("select ad_password from job_admins where ad_name='"+user+"'");
			while(rs.next()){
				String s = rs.getString("ad_password");
				if(pass.equals(new String(s))){
					bl = true;
				}
			}
		}catch(Exception e){}
		return bl;
	}
}
